import { StrategyOptions, Strategy, ExtractJwt } from "passport-jwt"
import { PassportStrategy } from "@nestjs/passport"
import { InjectRepository } from "@nestjs/typeorm"
import { UserDemo } from "src/Entities/UserDemo/UserDemo.dao"
import { Repository } from "typeorm"
import { Injectable } from "@nestjs/common"

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {

    constructor(@InjectRepository(UserDemo) private userDemo: Repository<UserDemo>) {
        super({
            jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
            secretOrKey: "fasdfdsafd,asfd.;fjd31n2sadsadasal;s"
        } as StrategyOptions)
    }

    //  验证逻辑
    async validate(username) {
        return await this.userDemo.find({
            where: { username }
        })
    }

}